package com.game.view.display
{
    import flash.display.BitmapData;
    
    public class TextureGroup
    {
        private var _textureVec:Vector.<Texture>;
        
        public function TextureGroup()
        {
            super();
            _textureVec = new Vector.<Texture>();
        }
        
        public function get textureVec():Vector.<Texture>
        {
            return _textureVec;
        }
        
        public function get length():int
        {
            return _textureVec.length;
        }
        
        public function addTexture(tex:Texture):void
        {
            _textureVec.push(tex);
        }
        
        public function removeTexture():void
        {
            _textureVec.pop();
        }
        
        public function addTextureAt(tex:Texture,idx:int):void
        {
            _textureVec.splice(idx,0,tex);
        }
        
        public function removeTextureAt(idx:int):void
        {
            (_textureVec[idx] as Texture).dispose();
            _textureVec.splice(idx,1);
        }
        
        public function setTextureAt(tex:Texture, idx:int):void
        {
            _textureVec[idx] = tex;
        }
        
        public function getTextureAt(idx:int):Texture
        {
            return _textureVec[idx];
        }
        
        public function getTextureViewAt(idx:int):BitmapData
        {
            return (_textureVec[idx] as Texture).content;
        }
        
        public function clearSameKeyFrame():void
        {
            for (var i:int = 0; i < _textureVec.length - 1; i++)
            {
                var texPre:Texture = _textureVec[i];
                var texNext:Texture = _textureVec[i + 1];
                var com:* = texPre.content.compare(texNext.content);
                if(typeof com == "number" && com == 0)
                {
                    texNext.content.dispose();
                    texNext.content = texPre.content;
                }
            }
        }
        
        public function destroy():void
        {
            while (_textureVec.length > 0)
            {
                (_textureVec[0] as Texture).dispose();
                _textureVec.shift();
            }
        }
    }
}
